using System;
using System.Collections.Generic;
using System.Text;

namespace TinyLogger
{
    public enum LogLevel { Debug, Informational, Warning, Error, Fatal };

    /// <summary>
    /// Interface description for creating custom loggers.
    /// </summary>
    public interface ILoggerSink
    {
        void AddLog(LogLevel level, string logString);
    }

    /// <summary>
    /// This logger will dispatch log messages to its LoggerSinks.
    /// The LogLevel defines if logging should occur for incoming log requests.
    /// </summary>
    public class Logger
    {
        private LogLevel setLevel;
        private CompositeLoggerSink sinks = new CompositeLoggerSink();

        public Logger(LogLevel level)
        {
            setLevel = level;
        }

        public void SetLevel(LogLevel level)
        {
            this.setLevel = level;
        }

        public void AddLog(LogLevel level, string logString)
        {
            if (level >= setLevel)
            {
                sinks.AddLog(level, logString);
            }
        }

        public void AddLog(LogLevel level, string fmt, params object[] args)
        {
            if (level >= setLevel)
            {
                this.AddLog(level, string.Format(fmt, args));
            }
        }

        public void AddLoggerSink(ILoggerSink sink)
        {
            sinks.AddLoggerSink(sink);
        }

        public bool RemoveLoggerSink(ILoggerSink sink)
        {
            return sinks.RemoveLoggerSink(sink);
        }


    }
}
